using UnityEngine;
using QFramework;

namespace Survivor
{
	public partial class RecoverHpItem : ViewController
	{
		void Start()
		{
			CollectedBox.OnTriggerEnter2DEvent(BeCollect).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		void BeCollect(Collider2D co)
		{
			if (co.GetComponent<CollectableArea>())
			{
				this.DestroyGameObjGracefully();
				Global.Hp.Value += Global.MaxHp.Value/2;
				if (Global.Hp.Value > Global.MaxHp.Value)
				{
					Global.Hp.Value = Global.MaxHp.Value;
				}

				AudioKit.PlaySound("RecoverHp");
			}
		}
	}
}
